﻿#ifndef df_macro_h__2013_12_10__0_10
#define df_macro_h__2013_12_10__0_10

#include "StdAfx.h"

#ifdef __cplusplus

#include "targetver.h"

#ifdef WIN32
#	include <tchar.h>
#else
#	undef __STRICT_ANSI__ 
#	ifndef _REENTRANT
#		define _REENTRANT //线程安全
#	endif
#endif

#include <stdio.h>
#include <assert.h>
#include <string.h>
#include <stdint.h>
#include <memory>
#include <array>
#include <iostream>
#include <string>
#include <sstream>
#include <fstream>
#include <vector>
#include <queue>
#include <list>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <functional>
#include <stdexcept>
#include <ctime>


#if __GNUC__ ||  _MSC_VER>=1800
#	define DF_VARIABLE_TEMPLATE
#	define DF_STD_ATOM
#	include <atomic>
#	include <chrono>
#	include <thread>

///禁用拷贝构造,与拷贝赋值
#	define DF_DISABLE_COPY_ASSIGN(_name) public:\
	_name(const _name &) = delete; \
	_name& operator=(const _name &) = delete;

#else

#	define DF_DISABLE_COPY_ASSIGN(_name) private:\
	_name(const _name &); \
	_name& operator=(const _name &);
#endif





#ifdef WIN32
#	include <windows.h>
#	include <Shlwapi.h>
#	define DF_STATIC_INIT __declspec(selectany)

#	if _MSC_VER>=1900
#		define DF_UTF_TEXT(_x) u8##_x
#	else
#		define DF_UTF_TEXT(_x) _x
#	endif
#else
#	include <unistd.h>
#	include <errno.h>
#	include <time.h>
#	include <sys/types.h>
#	include <sys/stat.h>
#	include <fcntl.h>
#	include <dirent.h>
#	define DF_STATIC_INIT __attribute__((weak))
#	define DF_UTF_TEXT(_x) u8##_x
#endif

#define DF_UTF8(_x) DF_UTF_TEXT(_x)

#ifndef FORCEINLINE
#	define FORCEINLINE inline
#endif



#ifndef _T
#	define _TEXT(_x) DF_UTF_TEXT(_x)
#	define _T(_x) _x
typedef uint32_t DWORD;
typedef char TCHAR;
typedef char _TCHAR;
#endif // !_T

#ifndef TRUE
#	define TRUE 1
#	define FALSE 0
#endif


#ifndef _trename
#	define _trename rename
#endif

#ifndef MAX_PATH
#	define MAX_PATH 512
#endif

#ifndef HAVE_TLS
#	define HAVE_TLS
#endif

#if  _MSC_VER < 1900
#	define DF_CONSTEXP const
#else
#	define DF_CONSTEXP constexpr
#endif

#if  defined _MSC_VER
#	if _MSC_VER >= 1900
#		define DF_THREAD_LOCAL_VAR thread_local
#	else
#		define DF_THREAD_LOCAL_VAR __declspec(thread)
#	endif
#elif defined(__APPLE__)
#	define DF_THREAD_LOCAL_VAR  
#else
#	define DF_THREAD_LOCAL_VAR thread_local
#endif

#ifdef _MSC_VER
#	pragma warning(disable:4535) // _set_se_translator() 需要 /EHa
#	pragma warning(disable:4127) // constant expression
#	pragma warning(disable:4510) // 未能生成默认构造函数
#	pragma warning(disable:4512) // 未能生成赋值运算符
#	pragma warning(disable:4610) // 永远不能实例化 - 需要用户定义的构造函数
#	pragma warning(disable:4131) // old-style declarator

#	define DF_NO_INLINE __declspec(noinline)
#	define DF_TEMPLATE 
#	define DF_SPRINT_A sprintf_s
#	define DF_SPRINT_W swprintf_s
#else

#	define DF_NO_INLINE 
#	define DF_TEMPLATE template
#	define DF_SPRINT_A snprintf
#	define DF_SPRINT_W snwprintf
#endif

namespace df
{
#ifdef UNICODE
#	define Cout std::wcout
	typedef std::wstring String;
#else
#	define Cout std::cout
	typedef std::string String;
#endif
}


#define DF_WIDE_C(_str) L##_str

#define tt_(_x) _T(_x)
#define tcc_(_x) df::CC(tt_(_x))
#define tccw_(_x) df::CCw(tt_(_x))
#define tcca_(_x) df::CCa(tt_(_x))
#define tccr_(_x) df::CC(_x)


#define DF_STR_CAT_(S) #S 
#define DF_STR_CAT(S) DF_STR_CAT_(S) 
#define DF_NAME_VALUE(M) DF_STR_CAT(M) 
#define DF_FILE_LINE _T(__FILE__) _T("(") _T(DF_NAME_VALUE(__LINE__)) _T(")")


#ifdef _DEBUG
#	define COUT(_x) Cout<<_x<<std::endl
#	define DF_ASSERT(_x) assert(_x)
#	ifdef WIN32
#		define DF_BREAK_POINT do{if(::MessageBoxA(::GetActiveWindow(),"触发断点?","断点",MB_OKCANCEL | MB_ICONQUESTION)==IDOK)::DebugBreak();}while(0)
#		define DF_BREAK_POINT_MSG(_msg) do{if(::MessageBoxA(::GetActiveWindow(),_msg,"触发断点?",MB_OKCANCEL | MB_ICONQUESTION)==IDOK)::DebugBreak();}while(0)
#	else
#		define DF_BREAK_POINT assert(false)
#		define DF_BREAK_POINT_MSG(_msg) assert(false)
#	endif
#else
#	define COUT(_x)
#	define DF_ASSERT(_x)
#	define DF_BREAK_POINT
#	define DF_BREAK_POINT_MSG(_msg) 
#endif


#define DF_MIX_LINENAME_CAT(_name, _line) _name##_line
#define DF_MIX_LINENAME(_name, _line) DF_MIX_LINENAME_CAT(_name, _line)

#endif

#endif // df_macro_h__2013_12_10__0_10
